package com.sxfq.loansupermarket.backsystem.core.util.qr;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 内嵌图片的二维码生成器
 *
 * @author py
 */
public class CreateQRCode {
    public static void main(String[] args) {
//        final int width = 300;
//        final int height = 300;
//        final String format = "png";
//        final String text = "http://118.123.15.60/logincus";
//        //定义二维码的参数
//        HashMap hints = new HashMap();
//        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
//        hints.put(EncodeHintType.MARGIN, 2);
//        try { // 生成二维码
//            BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
//            Path file = new File("D:/img.png").toPath();
//            MatrixToImageWriter.writeToPath(bitMatrix, format, file);
//        } catch (Exception e) {}
        final int width = 300;
        final int height = 300;
        final String format = "png";
        final String text = "http://test.yiyatest.cn:8787/integralMallWeixin/logincus";
        //定义二维码的参数
        HashMap hints = new HashMap();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
        hints.put(EncodeHintType.MARGIN, 2);
        try { // 生成二维码
            BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
            Path file = new File("D:/img.png").toPath();
            MatrixToImageWriter.writeToPath(bitMatrix, format, file);
//            Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "D:\\8068\\apache-tomcat-8.0.30\\webapps\\ROOT/wdyltblpx_img.png"});
        } catch (Exception e) {}
//        return "wdyltblpxzc_img.png";
    }

}